﻿using Engine.Media;
using GameEntitySystem;
using System.Collections;
using System.Xml.Linq;

namespace Game
{
	//指令编辑界面
	public class CommandEditWidget : CanvasWidget
	{
		public ButtonWidget m_commandNameButton;

		public ButtonWidget m_commandTypeButton;

		public ButtonWidget m_coordinateButton;

		public ButtonWidget m_collectInstructionButton;

		public ButtonWidget m_moreInstructionButton;

		public ButtonWidget m_workingModeButton;

		public ButtonWidget m_quickModeButton;

		public ButtonWidget m_submitButton;

		public ButtonWidget m_saveButton;

		public ButtonWidget m_cancelButton;

		public LabelWidget m_commandNameTitleLabel;

		public LabelWidget m_commandNameLabel;

		public LabelWidget m_commandTypeLabel;

		public LabelWidget m_coordinateLabel;

		public LabelWidget m_workingModeLabel;

		public LabelWidget m_quickModeLabel;

		public LabelWidget m_saveLabel;

		public LabelWidget m_instructionLabel;

		public RectangleWidget m_workingModeRectangle;

		public RectangleWidget m_quickModeRectangle;

		public RectangleWidget m_commandTypeRectangle;

		public RectangleWidget m_coordinateRectangle;

		public LabelWidget m_instructionScrollLabel;

		public CommandScrollPanelWidget m_instructionScrollPanel;

		public ScrollPanelWidget m_commandDataScrollPanelWidget;

		public StackPanelWidget m_commandDataWidget;

		public StackPanelWidget m_commandDataStaticWidget;

		public StackPanelWidget m_commandDataScrollWidget;

		public CanvasWidget m_submitCanvas;

		public Dictionary<string, Widget> m_commandWidgetDatas = new Dictionary<string, Widget>();

		public ComponentPlayer m_componentPlayer;

		public string m_name;

		public string m_type;

		public string m_coordinate;

		public Point3 m_position;

		public SubsystemCommandBlockBehavior m_subsystemCmdBlockBehavior;

		public SubsystemCmdRodBlockBehavior m_subsystemCmdRodBehavior;

		public SubsystemTerrain m_subsystemTerrain;

		public bool m_conditionMode = false;

		public bool m_fastMode;

		public static Dictionary<Point3, Vector2> ScrollPosition = new Dictionary<Point3, Vector2>();

		public CommandEditWidget(Project project, ComponentPlayer componentPlayer, Point3 position, bool fastMode = false)
		{
			m_componentPlayer = componentPlayer;
			m_position = position;
			m_fastMode = fastMode;
			m_subsystemCmdBlockBehavior = project.FindSubsystem<SubsystemCommandBlockBehavior>();
			m_subsystemCmdRodBehavior = project.FindSubsystem<SubsystemCmdRodBlockBehavior>();
			m_subsystemTerrain = project.FindSubsystem<SubsystemTerrain>();
			XElement node = ContentManager.Get<XElement>("Widgets/CommandEditWidget");
			LoadContents(this, node);
			m_commandNameButton = Children.Find<ButtonWidget>("CommandNameButton");
			m_commandTypeButton = Children.Find<ButtonWidget>("CommandTypeButton");
			m_coordinateButton = Children.Find<ButtonWidget>("CoordinateButton");
			m_collectInstructionButton = Children.Find<ButtonWidget>("CollectInstructionButton");
			m_moreInstructionButton = Children.Find<ButtonWidget>("MoreInstructionButton");
			m_workingModeButton = Children.Find<ButtonWidget>("WorkingModeButton");
			m_quickModeButton = Children.Find<ButtonWidget>("QuickModeButton");
			m_submitButton = Children.Find<ButtonWidget>("SubmitButton");
			m_saveButton = Children.Find<ButtonWidget>("SaveButton");
			m_cancelButton = Children.Find<ButtonWidget>("CancelButton");
			m_commandNameTitleLabel = Children.Find<LabelWidget>("CommandNameTitleLabel");
			m_commandNameLabel = Children.Find<LabelWidget>("CommandNameLabel");
			m_commandTypeLabel = Children.Find<LabelWidget>("CommandTypeLabel");
			m_coordinateLabel = Children.Find<LabelWidget>("CoordinateLabel");
			m_instructionLabel = Children.Find<LabelWidget>("InstructionLabel");
			m_workingModeLabel = Children.Find<LabelWidget>("WorkingModeLabel");
			m_quickModeLabel = Children.Find<LabelWidget>("QuickModeLabel");
			m_saveLabel = Children.Find<LabelWidget>("SaveLabel");
			m_workingModeRectangle = Children.Find<RectangleWidget>("WorkingModeRectangle");
			m_quickModeRectangle = Children.Find<RectangleWidget>("QuickModeRectangle");
			m_commandTypeRectangle = Children.Find<RectangleWidget>("CommandTypeRectangle");
			m_coordinateRectangle = Children.Find<RectangleWidget>("CoordinateRectangle");
			m_instructionScrollLabel = Children.Find<LabelWidget>("InstructionScrollLabel");
			m_instructionScrollPanel = Children.Find<CommandScrollPanelWidget>("InstructionScrollPanel");
			m_commandDataScrollPanelWidget = Children.Find<ScrollPanelWidget>("CommandDataScrollPanelWidget");
			m_commandDataStaticWidget = Children.Find<StackPanelWidget>("CommandDataStaticWidget");
			m_commandDataScrollWidget = Children.Find<StackPanelWidget>("CommandDataScrollWidget");
			m_submitCanvas = Children.Find<CanvasWidget>("SubmitCanvas");
			m_instructionScrollPanel.IsVisible = false;
			m_quickModeButton.IsVisible = false;
			CommandData commandData;
			if (m_fastMode)
			{
				commandData = new CommandData(Point3.Zero, m_subsystemCmdRodBehavior.m_commandLine);
				commandData.TrySetValue();
			}
			else
			{
				commandData = m_subsystemCmdBlockBehavior.GetCommandData(m_position);
			}
			Initialize();
			SetCommandDataValue(commandData);
			ChangeExplains();
			GetDynamicCommanndWidget();
			SetCommandWidgetValue(commandData);
			GuiWidgetControl(m_componentPlayer, false);
		}

		public override void Update()
		{
			if (m_commandNameButton.IsClicked)
			{
				Dictionary<string, Instruction> instructions = !m_conditionMode ? InstructionManager.FunInstructions : InstructionManager.ConInstructions;
				GameMode gameMode = m_componentPlayer.m_subsystemGameInfo.WorldSettings.GameMode;
				if (gameMode != GameMode.Creative)
				{
					instructions = InstructionManager.GetSurvivalList(instructions);
				}
				if (!ScrollPosition.TryGetValue(m_position, out Vector2 vector))
				{
					vector = Vector2.Zero;
					ScrollPosition[m_position] = vector;
				}
				DialogsManager.ShowDialog(m_componentPlayer.GuiWidget, new CommandListSelectionDialog(true, instructions.Values, 50f, vector.X, (object i) => new LabelWidget
				{
					Text = InstructionManager.GetDisplayName(((Instruction)i).Name) + " : " + ((Instruction)i).About,
					Color = (m_name == InstructionManager.GetDisplayName(((Instruction)i).Name)) ? Color.Green : Color.White,
					HorizontalAlignment = WidgetAlignment.Center,
					VerticalAlignment = WidgetAlignment.Center
				}, delegate (object i, float scroll)
				{
					ScrollPosition[m_position] = new Vector2(scroll, ScrollPosition[m_position].Y);
					if (i != null)
					{
						if (m_name != InstructionManager.GetDisplayName(((Instruction)i).Name))
						{
							m_name = InstructionManager.GetDisplayName(((Instruction)i).Name);
							m_type = ((Instruction)i).Types[0];
							m_commandNameLabel.Text = GetAbridgeText(m_name);
							m_commandTypeLabel.Text = GetAbridgeText(m_type);
							if (((Instruction)i).Types.Count <= 1)
							{
								m_commandTypeRectangle.FillColor = new Color(90, 90, 90);
							}
							else
							{
								m_commandTypeRectangle.FillColor = new Color(120, 120, 120);
							}
							CommandData commandData = new CommandData(Point3.Zero, string.Empty);
							SetCommandDataValue(commandData);
							ChangeExplains();
							GetDynamicCommanndWidget();
							SetCommandWidgetValue(commandData);
						}
					}
				}, delegate (TextBoxWidget textBox, ListPanelWidget listWidget)
				{
					listWidget.ClearItems();
					if (string.IsNullOrEmpty(textBox.Text))
					{
						foreach (object item in instructions.Values)
						{
							listWidget.AddItem(item);
						}
						return;
					}
					foreach (object item in instructions.Values)
					{
						string match = InstructionManager.GetDisplayName(((Instruction)item).Name) + ((Instruction)item).About;
						if (match.Contains(textBox.Text))
						{
							listWidget.AddItem(item);
						}
					}
				}));
			}
			if (m_commandTypeButton.IsClicked)
			{
				Instruction instruction = InstructionManager.GetInstruction(m_name, m_conditionMode);
				if (instruction == null) return;
				if (instruction.Types.Count < 2)
				{
					ShowEditTips(InstructionManager.GetDisplayName(instruction.Name) + "指令无其他命令类型");
					return;
				}
				if (!ScrollPosition.TryGetValue(m_position, out Vector2 vector))
				{
					vector = Vector2.Zero;
					ScrollPosition[m_position] = vector;
				}
				DialogsManager.ShowDialog(m_componentPlayer.GuiWidget, new CommandListSelectionDialog(true, instruction.Types, 50f, vector.Y, (object type) => new LabelWidget
				{
					Text = (string)type,
					Color = (m_type == (string)type) ? Color.Green : Color.White,
					HorizontalAlignment = WidgetAlignment.Center,
					VerticalAlignment = WidgetAlignment.Center
				}, delegate (object type, float scroll)
				{
					ScrollPosition[m_position] = new Vector2(ScrollPosition[m_position].X, scroll);
					if (type != null)
					{
						if (m_type != (string)type)
						{
							m_type = (string)type;
							m_commandTypeLabel.Text = GetAbridgeText(m_type);
							CommandData commandData = new CommandData(Point3.Zero, string.Empty);
							SetCommandDataValue(commandData);
							ChangeExplains();
							GetDynamicCommanndWidget();
							SetCommandWidgetValue(commandData);
						}
					}
				}, delegate (TextBoxWidget textBox, ListPanelWidget listWidget)
				{
					listWidget.ClearItems();
					if (string.IsNullOrEmpty(textBox.Text))
					{
						foreach (object item in instruction.Types)
						{
							listWidget.AddItem(item);
						}
						return;
					}
					foreach (object item in instruction.Types)
					{
						string match = (string)item + instruction.Details[(string)item];
						if (match.Contains(textBox.Text))
						{
							listWidget.AddItem(item);
						}
					}
				}));
			}
			if (m_coordinateButton.IsClicked)
			{
				if (m_fastMode)
				{
					ShowEditTips("快速指令界面只允许使用标准坐标");
					return;
				}
				else
				{
					string[] coordList = new string[3] { "default : 默认世界坐标", "command : 相对命令方块", "player : 相对当前玩家" };
					DialogsManager.ShowDialog(m_componentPlayer.GuiWidget, new CommandListSelectionDialog(false, coordList, 50f, 0f, (object coord) => new LabelWidget
					{
						Text = (string)coord,
						Color = ((string)coord).Contains(m_coordinate) ? Color.Green : Color.White,
						HorizontalAlignment = WidgetAlignment.Center,
						VerticalAlignment = WidgetAlignment.Center
					}, delegate (object coord, float scroll)
					{
						if (coord != null)
						{
							string coordtemp = ((string)coord).Replace(" ", "").Split(new char[1] { ':' })[0];
							if (m_coordinate != coordtemp)
							{
								m_coordinate = coordtemp;
								m_coordinateLabel.Text = m_coordinate;
							}
						}
					}, null));
				}
			}
			if (m_moreInstructionButton.IsClicked)
			{
				CommandEditHistoryWidget commandEditHistoryWidget = new CommandEditHistoryWidget(this, m_position, m_fastMode);
				base.ParentWidget.Children.Add(commandEditHistoryWidget);
			}
			if (m_collectInstructionButton.IsClicked)
			{
				SaveCommandData(true);
				ShowEditTips("已收藏当前指令");
			}
			if (m_workingModeButton.IsClicked)
			{
				if (m_fastMode)
				{
					m_subsystemCmdRodBehavior.m_subsystemCommand.m_canWorking = !m_subsystemCmdRodBehavior.m_subsystemCommand.m_canWorking;
					if (m_subsystemCmdRodBehavior.m_subsystemCommand.m_canWorking)
					{
						m_workingModeRectangle.FillColor = new Color(120, 120, 120);
						ShowEditTips("已开启指令的功能运作");
					}
					else
					{
						m_workingModeRectangle.FillColor = new Color(80, 80, 80);
						ShowEditTips("已关闭指令的功能运作");
					}
				}
				else
				{
					m_conditionMode = !m_conditionMode;
					CommandData commandData = new CommandData(Point3.Zero, string.Empty);
					Initialize();
					SetCommandDataValue(commandData);
					ChangeExplains();
					GetDynamicCommanndWidget();
					SetCommandWidgetValue(commandData);
				}
			}
			if (m_quickModeButton.IsClicked)
			{
				SubsystemCmdRodBlockBehavior.QuickMode = !SubsystemCmdRodBlockBehavior.QuickMode;
				if (SubsystemCmdRodBlockBehavior.QuickMode)
				{
					WithdrawBlockManager.WithdrawMode = true;
					m_quickModeRectangle.FillColor = new Color(120, 120, 120);
					ShowEditTips("已开启快捷模式，可在命令手册查看使用说明", 3);
				}
				else
				{
					m_quickModeRectangle.FillColor = new Color(80, 80, 80);
					ShowEditTips("已关闭快捷模式");
				}
			}
			if (m_cancelButton.IsClicked || base.Input.Cancel || base.Input.Back)
			{
				GuiWidgetControl(m_componentPlayer, true);
				base.ParentWidget.Children.Remove(this);
			}
			if (m_saveButton.IsClicked)
			{
				if(m_componentPlayer.m_subsystemGameInfo.WorldSettings.GameMode == GameMode.Creative)
				{SaveCommandData(false);}
				else
				{ShowEditTips("仅限创造模式");}
				GuiWidgetControl(m_componentPlayer, true);
				base.ParentWidget.Children.Remove(this);
			}
			if (m_submitButton.IsClicked && m_fastMode)
			{
				if(m_componentPlayer.m_subsystemGameInfo.WorldSettings.GameMode == GameMode.Creative)
				{
					CommandData commandData = SaveCommandData(false);
					if(commandData.Mode == WorkingMode.执行)
					{
						SubmitResult submitResult = m_subsystemCmdRodBehavior.m_subsystemCommand.Submit(commandData.Name,commandData,false);
						switch(submitResult)
						{
							case SubmitResult.Success: ShowEditTips("指令提交成功"); break;
							case SubmitResult.Fail: ShowEditTips("指令提交失败"); break;
							case SubmitResult.Exception: ShowEditTips("指令在执行时发生了异常"); break;
							case SubmitResult.Invalid: ShowEditTips("编辑的指令不符合格式要求"); break;
							case SubmitResult.NoFound: ShowEditTips("当前指令不存在"); break;
							case SubmitResult.OutRange: ShowEditTips("指令存在超出范围的参数"); break;
						}
						if(submitResult == SubmitResult.Success)
						{
							Time.QueueTimeDelayedExecution(Time.RealTime + 0.2f,delegate
							{
								GuiWidgetControl(m_componentPlayer,true);
								if(base.ParentWidget != null)
								{
									base.ParentWidget.Children.Remove(this);
								}
							});
						}
					}
					else if(commandData.Mode == WorkingMode.条件)
					{
						ShowEditTips("快速指令功能不支持条件指令");
					}
					else if(commandData.Mode == WorkingMode.变量)
					{
						ShowEditTips("快速指令功能不支持指令变量");
					}
				}
				else
				{
					ShowEditTips("只有创造模式可以修改指令");
				}
			}
			try
			{
				UpdateCommandWidget();
			}
			catch (Exception e)
			{
				Log.Warning("UpdateCommandWidget:" + e.Message);
			}
		}

		//更新界面
		public void UpdateCommandWidget()
		{
			foreach (string key in m_commandWidgetDatas.Keys)
			{
				if (key.Contains("Button") && ((ButtonWidget)m_commandWidgetDatas[key]).IsClicked)
				{
					string[] widgetPara = key.Split(new char[1] { '$' });
					if (widgetPara[0] == "BlockButton")
					{
						CommandBlockSelectionWidget blockSelectionWidget = new CommandBlockSelectionWidget(this, m_componentPlayer.Entity, widgetPara[1]);
						base.ParentWidget.Children.Add(blockSelectionWidget);
					}
					else if (widgetPara[0] == "ModelButton")
					{
						CommandEntitySelectionWidget entitySelectionWidget = new CommandEntitySelectionWidget(this, widgetPara[1]);
						base.ParentWidget.Children.Add(entitySelectionWidget);
					}
					else if (widgetPara[0] == "ColorButton")
					{
						CommandColorSelectionWidget colorSelectionWidget = new CommandColorSelectionWidget(this, widgetPara[1]);
						base.ParentWidget.Children.Add(colorSelectionWidget);
					}
					else if (widgetPara[0] == "ActionButton")
					{
						if (widgetPara[1].StartsWith("id"))
						{
							if (m_subsystemCmdRodBehavior.m_recordBlockValue.HasValue)
							{
								int value = m_subsystemCmdRodBehavior.m_recordBlockValue.Value;
								TextBoxWidget textBoxWidget = (TextBoxWidget)m_commandWidgetDatas["TextBox$" + widgetPara[1]];
								BlockIconWidget blockIconWidget = (BlockIconWidget)m_commandWidgetDatas["BlockIcon$" + widgetPara[1]];
								textBoxWidget.Text = value + "";
								blockIconWidget.Value = value;
							}
							else
							{
								ShowEditTips("请先用命令辅助棒点击方块获取信息", 5);
							}
						}
						else if (widgetPara[1].StartsWith("obj"))
						{
							if (m_subsystemCmdRodBehavior.m_recordEntityName != null)
							{
								string name = m_subsystemCmdRodBehavior.m_recordEntityName;
								TextBoxWidget textBoxWidget = (TextBoxWidget)m_commandWidgetDatas["TextBox$" + widgetPara[1]];
								ModelWidget modelWidget = (ModelWidget)m_commandWidgetDatas["Model$" + widgetPara[1]];
								textBoxWidget.Text = name;
								ChangeModelWidget(name, modelWidget);
							}
							else
							{
								ShowEditTips("请先用命令辅助棒点击动物获取信息", 5);
							}
						}
						else if (widgetPara[1].StartsWith("pos"))
						{
							if (m_subsystemCmdRodBehavior.m_recordPosition.HasValue)
							{
								Point3 point = m_subsystemCmdRodBehavior.m_recordPosition.Value;
								TextBoxWidget textBoxWidget = (TextBoxWidget)m_commandWidgetDatas["TextBox$" + widgetPara[1]];
								textBoxWidget.Text = point.X + "," + point.Y + "," + point.Z;
							}
							else
							{
								ShowEditTips("请先用命令辅助棒点击方块获取信息", 5);
							}
						}
						else if (widgetPara[1].StartsWith("eyes"))
						{
							if (m_subsystemCmdRodBehavior.m_recordEyes.HasValue)
							{
								Point2 eyes = m_subsystemCmdRodBehavior.m_recordEyes.Value;
								TextBoxWidget textBoxWidget = (TextBoxWidget)m_commandWidgetDatas["TextBox$" + widgetPara[1]];
								textBoxWidget.Text = eyes.X + "," + eyes.Y;
							}
							else
							{
								ShowEditTips("请先用命令辅助棒点击屏幕获取信息", 5);
							}
						}
						else if (widgetPara[1].StartsWith("fid"))
						{
							if (m_subsystemCmdRodBehavior.m_recordfurnitureId.HasValue)
							{
								int fid = m_subsystemCmdRodBehavior.m_recordfurnitureId.Value;
								TextBoxWidget textBoxWidget = (TextBoxWidget)m_commandWidgetDatas["TextBox$" + widgetPara[1]];
								textBoxWidget.Text = fid + "";
							}
							else
							{
								ShowEditTips("请先用命令辅助棒点击家具获取信息", 5);
							}
						}
						else if (widgetPara[1].StartsWith("cid"))
						{
							if (m_subsystemCmdRodBehavior.m_recordclothesId.HasValue)
							{
								int cid = m_subsystemCmdRodBehavior.m_recordclothesId.Value;
								TextBoxWidget textBoxWidget = (TextBoxWidget)m_commandWidgetDatas["TextBox$" + widgetPara[1]];
								textBoxWidget.Text = cid + "";
							}
							else
							{
								ShowEditTips("请先用命令辅助棒点击衣物掉落物获取信息", 5);
							}
						}
						else if (widgetPara[1].StartsWith("opt"))
						{
							string[] options = InstructionManager.GetInstructionOption(m_name, m_type, widgetPara[1], m_conditionMode);
							if (options != null)
							{
								DialogsManager.ShowDialog(null, new CommandListSelectionDialog(false, options, 50f, 0f, (object option) => new LabelWidget
								{
									Text = ((string)option).Contains(":") ? ((string)option).Split(new char[1] { ':' })[0] + " : " + ((string)option).Split(new char[1] { ':' })[1] : (string)option,
									HorizontalAlignment = WidgetAlignment.Center,
									VerticalAlignment = WidgetAlignment.Center
								}, delegate (object option, float scroll)
								{
									if (option != null)
									{
										string textValue = (string)option;
										if (textValue.Contains(":"))
										{
											textValue = textValue.Split(new char[1] { ':' })[0].Replace(" ", "");
										}
										TextBoxWidget textBoxWidget = (TextBoxWidget)m_commandWidgetDatas["TextBox$" + widgetPara[1]];
										textBoxWidget.Text = textValue;
									}
								}, null));
							}
							else
							{
								ShowEditTips("暂无可供选择的值", 5);
							}
						}
					}
				}
			}
		}

		//初始化
		public void Initialize()
		{
			Dictionary<string, Instruction> instructions = !m_conditionMode ? InstructionManager.FunInstructions : InstructionManager.ConInstructions;
			foreach (var instruction in instructions.Values)
			{
				m_name = InstructionManager.GetDisplayName(instruction.Name);
				m_type = instruction.Types[0];
				m_coordinate = "default";
				m_commandNameLabel.Text = GetAbridgeText(m_name);
				m_commandTypeLabel.Text = GetAbridgeText(m_type);
				m_coordinateLabel.Text = m_coordinate;
				break;
			}
			m_commandNameTitleLabel.Text = "功能指令:";
			m_workingModeLabel.Text = "功能执行";
			m_submitCanvas.IsVisible = m_fastMode;
			if (m_fastMode)
			{
				m_workingModeLabel.Text = "指令运作";
				m_saveLabel.Text = "保存";
				m_coordinateRectangle.FillColor = new Color(90, 90, 90);
				if (m_subsystemCmdRodBehavior.m_subsystemCommand.m_canWorking)
				{
					m_workingModeRectangle.FillColor = new Color(120, 120, 120);
				}
				else
				{
					m_workingModeRectangle.FillColor = new Color(80, 80, 80);
				}
				m_quickModeButton.IsVisible = true;
				m_quickModeLabel.Text = "快捷模式";
				if (SubsystemCmdRodBlockBehavior.QuickMode)
				{
					m_quickModeRectangle.FillColor = new Color(120, 120, 120);
				}
				else
				{
					m_quickModeRectangle.FillColor = new Color(80, 80, 80);
				}
			}
		}

		//设置命令数据
		public void SetCommandDataValue(CommandData commandData)
		{
			if (commandData != null && string.IsNullOrEmpty(commandData.Line))
			{
				commandData.Line = InstructionManager.GetInstructionDemo(m_name, m_type, m_conditionMode);
				commandData.TrySetValue();
			}
			else if (commandData != null && !string.IsNullOrEmpty(commandData.Line))
			{
				m_name = commandData.Name;
				m_type = commandData.Type;
				m_commandNameLabel.Text = GetAbridgeText(m_name);
				m_commandTypeLabel.Text = GetAbridgeText(m_type);
				if (commandData.Coordinate == CoordinateMode.相对) m_coordinate = "command";
				else if (commandData.Coordinate == CoordinateMode.玩家) m_coordinate = "player";
				else m_coordinate = "default";
				m_coordinateLabel.Text = m_coordinate;
				m_conditionMode = (commandData.Mode == WorkingMode.条件);

			}
		}

		//改变说明
		public void ChangeExplains()
		{
			m_instructionLabel.Text = "说明：" + InstructionManager.GetInstructionDetail(m_name, m_type, m_conditionMode);
			m_instructionScrollLabel.Text = m_instructionLabel.Text;
			if (m_instructionLabel.Text.Length > 25f)
			{
				m_instructionLabel.IsVisible = false;
				m_instructionScrollPanel.IsVisible = true;
			}
			else
			{
				m_instructionLabel.IsVisible = true;
				m_instructionScrollPanel.IsVisible = false;
			}
			if (!m_fastMode)
			{
				m_commandNameTitleLabel.Text = !m_conditionMode ? "功能指令:" : "条件指令:";
				m_workingModeLabel.Text = !m_conditionMode ? "功能执行" : "条件判断";
			}
		}

		//构造参数界面
		public void GetDynamicCommanndWidget()
		{
			int num = 0;
			Instruction instruction = InstructionManager.GetInstruction(m_name, m_conditionMode);
			if (instruction == null) instruction = InstructionManager.FunInstructions.Values.FirstOrDefault();
			m_commandTypeRectangle.FillColor = (instruction.Types.Count <= 1) ? new Color(90, 90, 90) : new Color(120, 120, 120);
			if (instruction == null) goto NoPataValue;
			int parasLength = instruction.Paras[m_type].Length;
			if (parasLength > 5)
			{
				m_commandDataScrollPanelWidget.IsVisible = true;
				m_commandDataStaticWidget.IsVisible = false;
				m_commandDataWidget = m_commandDataScrollWidget;
			}
			else
			{
				m_commandDataScrollPanelWidget.IsVisible = false;
				m_commandDataStaticWidget.IsVisible = true;
				m_commandDataWidget = m_commandDataStaticWidget;
			}
			m_commandWidgetDatas.Clear();
			m_commandDataWidget.ClearChildren();
			if (m_name == "book")
			{
				XElement node = ContentManager.Get<XElement>("Widgets/CommandBookBox");
				ContainerWidget containerWidget = (ContainerWidget)LoadWidget(this, node, null);
				m_commandDataWidget.AddChildren(containerWidget);
				return;
			}
			int num2 = (parasLength >= 5) ? 20 : 30;
			if (parasLength > 5)
			{
				CanvasWidget canvasWidget = new CanvasWidget();
				canvasWidget.Size = new Vector2(0, num2);
				m_commandDataWidget.AddChildren(canvasWidget);
			}
			foreach (string para in instruction.Paras[m_type])
			{
				if (!InstructionManager.IsFixedParameter(para))
				{
					if (num != 0)
					{
						CanvasWidget canvasWidget = new CanvasWidget();
						canvasWidget.Size = new Vector2(0, num2);
						m_commandDataWidget.AddChildren(canvasWidget);
					}
					if (para.StartsWith("id"))
					{
						XElement node = ContentManager.Get<XElement>("Widgets/CommandBlockBox");
						ContainerWidget containerWidget = (ContainerWidget)LoadWidget(this, node, null);
						LabelWidget labelWidget = containerWidget.Children.Find<LabelWidget>("CommandData.Label");
						labelWidget.Text = InstructionManager.GetParameterName(m_name, m_type, para, m_conditionMode) + ":";
						TextBoxWidget textBoxWidget = containerWidget.Children.Find<TextBoxWidget>("CommandData.TextBox");
						BlockIconWidget blockIconWidget = containerWidget.Children.Find<BlockIconWidget>("CommandData.BlockIcon");
						blockIconWidget.Value = 46;
						ButtonWidget buttonWidget = containerWidget.Children.Find<ButtonWidget>("CommandData.BlockButton");
						ButtonWidget buttonWidget2 = containerWidget.Children.Find<ButtonWidget>("CommandData.ActionButton");
						m_commandDataWidget.AddChildren(containerWidget);
						m_commandWidgetDatas.Add("TextBox$" + para, textBoxWidget);
						m_commandWidgetDatas.Add("BlockIcon$" + para, blockIconWidget);
						m_commandWidgetDatas.Add("BlockButton$" + para, buttonWidget);
						m_commandWidgetDatas.Add("ActionButton$" + para, buttonWidget2);
						textBoxWidget.TextChanged += delegate (TextBoxWidget boxWidget)
						{
							ChangeBlockIconWidget(boxWidget.Text, blockIconWidget);
						};
					}
					else if (para.StartsWith("obj"))
					{
						XElement node = ContentManager.Get<XElement>("Widgets/CommandEntityBox");
						ContainerWidget containerWidget = (ContainerWidget)LoadWidget(this, node, null);
						LabelWidget labelWidget = containerWidget.Children.Find<LabelWidget>("CommandData.Label");
						labelWidget.Text = InstructionManager.GetParameterName(m_name, m_type, para, m_conditionMode) + ":";
						TextBoxWidget textBoxWidget = containerWidget.Children.Find<TextBoxWidget>("CommandData.TextBox");
						ModelWidget modelWidget = containerWidget.Children.Find<ModelWidget>("CommandData.ModelIcon");
						EntityInfoManager.ChangeModelDisplay(ref modelWidget, "Models/Tiger", "Textures/Creatures/Tiger");
						ButtonWidget buttonWidget = containerWidget.Children.Find<ButtonWidget>("CommandData.ModelButton");
						ButtonWidget buttonWidget2 = containerWidget.Children.Find<ButtonWidget>("CommandData.ActionButton");
						m_commandDataWidget.AddChildren(containerWidget);
						m_commandWidgetDatas.Add("TextBox$" + para, textBoxWidget);
						m_commandWidgetDatas.Add("Model$" + para, modelWidget);
						m_commandWidgetDatas.Add("ModelButton$" + para, buttonWidget);
						m_commandWidgetDatas.Add("ActionButton$" + para, buttonWidget2);
						textBoxWidget.TextChanged += delegate (TextBoxWidget boxWidget)
						{
							ChangeModelWidget(boxWidget.Text, modelWidget);
						};
					}
					else if (para.StartsWith("color"))
					{
						XElement node = ContentManager.Get<XElement>("Widgets/CommandColorBox");
						ContainerWidget containerWidget = (ContainerWidget)LoadWidget(this, node, null);
						LabelWidget labelWidget = containerWidget.Children.Find<LabelWidget>("CommandData.Label");
						labelWidget.Text = InstructionManager.GetParameterName(m_name, m_type, para, m_conditionMode) + ":";
						TextBoxWidget textBoxWidget = containerWidget.Children.Find<TextBoxWidget>("CommandData.TextBox");
						RectangleWidget rectangleWidget = containerWidget.Children.Find<RectangleWidget>("CommandData.ColorPanel");
						rectangleWidget.FillColor = new Color(100, 100, 100, 255);
						ButtonWidget buttonWidget = containerWidget.Children.Find<ButtonWidget>("CommandData.ColorButton");
						m_commandDataWidget.AddChildren(containerWidget);
						m_commandWidgetDatas.Add("TextBox$" + para, textBoxWidget);
						m_commandWidgetDatas.Add("Rectangle$" + para, rectangleWidget);
						m_commandWidgetDatas.Add("ColorButton$" + para, buttonWidget);
						textBoxWidget.TextChanged += delegate (TextBoxWidget boxWidget)
						{
							ChangeRectangleWidget(boxWidget.Text, rectangleWidget);
						};
					}
					else if (para.StartsWith("pos") || para.StartsWith("eyes") || para.StartsWith("fid") || para.StartsWith("cid") || para.StartsWith("opt"))
					{
						XElement node = ContentManager.Get<XElement>("Widgets/CommandTextButtonBox");
						ContainerWidget containerWidget = (ContainerWidget)LoadWidget(this, node, null);
						LabelWidget labelWidget = containerWidget.Children.Find<LabelWidget>("CommandData.Label");
						labelWidget.Text = InstructionManager.GetParameterName(m_name, m_type, para, m_conditionMode) + ":";
						TextBoxWidget textBoxWidget = containerWidget.Children.Find<TextBoxWidget>("CommandData.TextBox");
						ButtonWidget buttonWidget = containerWidget.Children.Find<ButtonWidget>("CommandData.ActionButton");
						m_commandDataWidget.AddChildren(containerWidget);
						m_commandWidgetDatas.Add("TextBox$" + para, textBoxWidget);
						m_commandWidgetDatas.Add("ActionButton$" + para, buttonWidget);
					}
					else if (para.StartsWith("con"))
					{
						XElement node = ContentManager.Get<XElement>("Widgets/CommandSwitchBox");
						ContainerWidget containerWidget = (ContainerWidget)LoadWidget(this, node, null);
						LabelWidget labelWidget = containerWidget.Children.Find<LabelWidget>("CommandData.Label");
						labelWidget.Text = InstructionManager.GetParameterName(m_name, m_type, para, m_conditionMode) + ":";
						CommandSwitchWidget switchWidget = containerWidget.Children.Find<CommandSwitchWidget>("CommandData.SwitchWidget");
						m_commandWidgetDatas.Add("Switch$" + para, switchWidget);
						m_commandDataWidget.AddChildren(containerWidget);
					}
					else
					{
						if (instruction.Ranges.TryGetValue(m_type + "$" + para, out Point2 range))
						{
							XElement node = ContentManager.Get<XElement>("Widgets/CommandSliderBox");
							ContainerWidget containerWidget = (ContainerWidget)LoadWidget(this, node, null);
							LabelWidget labelWidget = containerWidget.Children.Find<LabelWidget>("CommandData.Label");
							labelWidget.Text = InstructionManager.GetParameterName(m_name, m_type, para, m_conditionMode) + ":";
							CommandSliderWidget sliderWidget = containerWidget.Children.Find<CommandSliderWidget>("CommandData.Slider");
							TextBoxWidget textBoxWidget = sliderWidget.m_textBoxWidget;
							sliderWidget.MinValue = range.X;
							sliderWidget.MaxValue = range.Y;
							m_commandDataWidget.AddChildren(containerWidget);
							m_commandWidgetDatas.Add("Slider$" + para, sliderWidget);
							m_commandWidgetDatas.Add("TextBox$" + para, textBoxWidget);
						}
						else
						{
							XElement node = ContentManager.Get<XElement>("Widgets/CommandTextBox");
							ContainerWidget containerWidget = (ContainerWidget)LoadWidget(this, node, null);
							LabelWidget labelWidget = containerWidget.Children.Find<LabelWidget>("CommandData.Label");
							labelWidget.Text = InstructionManager.GetParameterName(m_name, m_type, para, m_conditionMode) + ":";
							TextBoxWidget textBoxWidget = containerWidget.Children.Find<TextBoxWidget>("CommandData.TextBox");
							m_commandDataWidget.AddChildren(containerWidget);
							m_commandWidgetDatas.Add("TextBox$" + para, textBoxWidget);
						}
					}
					num++;
				}
			}
			if (parasLength > 5)
			{
				CanvasWidget canvasWidget = new CanvasWidget();
				canvasWidget.Size = new Vector2(0, num2);
				m_commandDataWidget.AddChildren(canvasWidget);
			}
		NoPataValue:
			if (num == 0)
			{
				LabelWidget labelWidget = new LabelWidget();
				labelWidget.Text = "暂无参数";
				labelWidget.Color = Color.White;
				labelWidget.HorizontalAlignment = WidgetAlignment.Center;
				labelWidget.VerticalAlignment = WidgetAlignment.Center;
				m_commandDataWidget.AddChildren(labelWidget);
			}
		}

		//设置参数的值
		public void SetCommandWidgetValue(CommandData commandData)
		{
			foreach (string key in m_commandWidgetDatas.Keys)
			{
				string[] widgetPara = key.Split(new char[1] { '$' });
				if (commandData.DataText.TryGetValue(widgetPara[1], out string dataText))
				{
					if (widgetPara[0] == "TextBox")
					{
						((TextBoxWidget)m_commandWidgetDatas[key]).Text = dataText;
					}
					else if (widgetPara[0] == "BlockIcon")
					{
						ChangeBlockIconWidget(dataText, ((BlockIconWidget)m_commandWidgetDatas[key]));
					}
					else if (widgetPara[0] == "Model")
					{
						ChangeModelWidget(dataText, ((ModelWidget)m_commandWidgetDatas[key]));
					}
					else if (widgetPara[0] == "Rectangle")
					{
						ChangeRectangleWidget(dataText, ((RectangleWidget)m_commandWidgetDatas[key]));
					}
					else if (widgetPara[0] == "Slider")
					{
						ChangeSliderWidget(dataText, ((CommandSliderWidget)m_commandWidgetDatas[key]));
					}
					else if (widgetPara[0] == "Switch")
					{
						((CommandSwitchWidget)m_commandWidgetDatas[key]).m_checkLabelText = dataText;
					}
				}
			}
		}

		//改变方块图标
		public void ChangeBlockIconWidget(string dataText, BlockIconWidget blockIconWidget)
		{
			if (int.TryParse(dataText, out int num))
			{
				blockIconWidget.IsVisible = true;
				blockIconWidget.Value = num;
			}
			else
			{
				blockIconWidget.IsVisible = false;
			}
		}

		//改变模型图标
		public void ChangeModelWidget(string dataText, ModelWidget modelWidget)
		{
			dataText = dataText.ToLower();
			EntityInfo modelInfo = EntityInfoManager.GetEntityInfo(dataText);
			if (modelInfo != null)
			{
				modelWidget.IsVisible = true;
				EntityInfoManager.ChangeModelDisplay(ref modelWidget, modelInfo.Model, modelInfo.Texture);
			}
			else
			{
				modelWidget.IsVisible = false;
			}
		}

		//改变长方体颜色块
		public void ChangeRectangleWidget(string dataText, RectangleWidget rectangleWidget)
		{
			try
			{
				Color color = DataHandle.GetColorValue(dataText);
				if (!((dataText != "255,255,255" && dataText != "255,255,255,255") && color == Color.White))
				{
					rectangleWidget.FillColor = color;
				}
				else
				{
					rectangleWidget.FillColor = new Color(100, 100, 100, 255);
				}
			}
			catch
			{
				rectangleWidget.FillColor = new Color(100, 100, 100, 255);
			}
		}

		//改变滑条
		public void ChangeSliderWidget(string dataText, CommandSliderWidget sliderWidget)
		{
			if (int.TryParse(dataText, out int num) && num >= sliderWidget.MinValue && num <= sliderWidget.MaxValue)
			{
				sliderWidget.Value = num;
			}
			else
			{
				sliderWidget.Value = sliderWidget.MinValue;
			}
		}

		//获取命令字符串
		public string GetCommandLines()
		{
			string dataLines = (!m_conditionMode ? "cmd:" : "if:") + m_name + " type:" + m_type;
			switch (m_coordinate)
			{
				case "command": dataLines += " cd:@c"; break;
				case "player": dataLines += " cd:@pl"; break;
				default: break;
			}
			foreach (var key in m_commandWidgetDatas.Keys)
			{
				string[] widgetPara = key.Split(new char[1] { '$' });
				if (widgetPara[0] == "TextBox")
				{
					dataLines += " " + widgetPara[1] + ":" + ((TextBoxWidget)m_commandWidgetDatas[key]).Text;
				}
				else if (widgetPara[0] == "Switch")
				{
					dataLines += " " + widgetPara[1] + ":" + ((CommandSwitchWidget)m_commandWidgetDatas[key]).m_checkLabelText;
				}
			}
			return dataLines;
		}

		//保存指令数据
		public CommandData SaveCommandData(bool collection)
		{
			string line = GetCommandLines();
			CommandData commandData = null;
			if (m_fastMode)
			{
				m_subsystemCmdRodBehavior.m_commandLine = line;
				commandData = new CommandData(Point3.Zero, line);
				commandData.TrySetValue();
				m_subsystemCmdRodBehavior.InitPointDataWidget();
			}
			else
			{
				commandData = m_subsystemCmdBlockBehavior.SetCommandData(m_position, line);
				int value = m_subsystemTerrain.Terrain.GetCellValue(m_position.X, m_position.Y, m_position.Z);
				m_subsystemTerrain.ChangeCell(m_position.X, m_position.Y, m_position.Z, 命令方块.SetWorkingMode(value, commandData.Mode));
			}
			HistoryEditItem historyEditItem = GetHistoryEditItem(commandData, collection);
			if (historyEditItem != null)
			{
				InstructionManager.AddHistoryItem(historyEditItem);
			}
			return commandData;
		}

		//获取指令编辑历史项
		public HistoryEditItem GetHistoryEditItem(CommandData commandData, bool collection)
		{
			HistoryEditItem historyEditItem = new HistoryEditItem();
			Instruction instruction = InstructionManager.GetInstruction(m_name, m_conditionMode);
			if (instruction == null) return null;
			historyEditItem.About = instruction.About.Replace("\r", "");
			historyEditItem.Line = commandData.Line;
			historyEditItem.Position = m_fastMode ? new Point3(m_componentPlayer.ComponentBody.Position) : commandData.Position;
			historyEditItem.Pass = (commandData.Valid && !commandData.OutRange);
			historyEditItem.Condition = (commandData.Mode == WorkingMode.条件);
			historyEditItem.Collection = collection;
			return historyEditItem;
		}

		//展示编辑说明
		public void ShowEditTips(string tip, int time = 2)
		{
			m_instructionLabel.Text = "提示：" + tip;
			m_instructionScrollLabel.Text = m_instructionLabel.Text;
			m_instructionLabel.Color = Color.Yellow;
			m_instructionScrollLabel.Color = Color.Yellow;
			m_instructionLabel.IsVisible = true;
			m_instructionScrollPanel.IsVisible = false;
			Time.QueueTimeDelayedExecution(Time.RealTime + time, delegate
			{
				ChangeExplains();
				m_instructionLabel.Color = Color.White;
				m_instructionScrollLabel.Color = Color.White;
			});
		}

		//获取文本缩写形式
		public string GetAbridgeText(string text)
		{
			if (text.Length > 12)
			{
				return text.Substring(0, 5) + "..." + text.Substring(text.Length - 5, 5);
			}
			return text;
		}

		//更改GUI控制
		public static void GuiWidgetControl(ComponentPlayer componentPlayer, bool button)
		{
			componentPlayer.ComponentGui.m_lookContainerWidget.IsVisible = button;
			componentPlayer.ComponentGui.m_moveContainerWidget.IsVisible = button;
			componentPlayer.ComponentGui.m_leftControlsContainerWidget.IsVisible = button;
			componentPlayer.ComponentGui.m_rightControlsContainerWidget.IsVisible = button;
			if (componentPlayer.ComponentGui.ShortInventoryWidget.m_inventory != null)
			{
				componentPlayer.ComponentGui.ShortInventoryWidget.IsVisible = button;
			}
			componentPlayer.ComponentInput.AllowHandleInput = button;
		}
	}

	//指令编辑历史界面
	public class CommandEditHistoryWidget : CanvasWidget
	{
		public ButtonWidget m_okButton;

		public ButtonWidget m_filterButton;

		public ButtonWidget m_clearButton;

		public LabelWidget m_filterLabel;

		public LabelWidget m_removeLabel;

		public RectangleWidget m_removeRectangle;

		public ListPanelWidget m_instructionlistWidget;

		public CommandEditWidget m_commandEditWidget;

		public bool m_filter;

		public bool m_fastMode;

		public CommandEditHistoryWidget(CommandEditWidget commandEditWidget, Point3 pos, bool fast)
		{
			m_commandEditWidget = commandEditWidget;
			m_commandEditWidget.IsEnabled = false;
			m_fastMode = fast;
			m_filter = true;
			XElement node = ContentManager.Get<XElement>("Widgets/CommandEditHistoryWidget");
			LoadContents(this, node);
			m_instructionlistWidget = Children.Find<ListPanelWidget>("EditHistory.List");
			m_okButton = Children.Find<ButtonWidget>("OkButton");
			m_filterButton = Children.Find<ButtonWidget>("FilterButton");
			m_clearButton = Children.Find<ButtonWidget>("ClearButton");
			m_filterLabel = Children.Find<LabelWidget>("FilterLabel");
			m_removeLabel = Children.Find<LabelWidget>("RemoveLabel");
			m_removeRectangle = Children.Find<RectangleWidget>("RemoveRectangle");
			UpdateItems();
			m_instructionlistWidget.ItemWidgetFactory = delegate (object item)
			{
				HistoryEditItem historyEditItem = (HistoryEditItem)item;
				XElement node2 = ContentManager.Get<XElement>("Widgets/HistoryEditItem");
				ContainerWidget containerWidget = (ContainerWidget)LoadWidget(this, node2, null);
				string title = string.Format("{0}   编辑位置:({1})", historyEditItem.About, historyEditItem.Position.ToString());
				Color passColor = historyEditItem.Pass ? new Color(32, 255, 32, 160) : new Color(255, 32, 32, 160);
				containerWidget.Children.Find<RectangleWidget>("PassRectangle").FillColor = passColor;
				containerWidget.Children.Find<LabelWidget>("HistoryEditItem.About").Text = title;
				containerWidget.Children.Find<LabelWidget>("HistoryEditItem.Line").Text = historyEditItem.Line;
				return containerWidget;
			};
			m_instructionlistWidget.ItemClicked += delegate (object item)
			{
				if (m_instructionlistWidget.SelectedItem == item)
				{
					HistoryEditItem historyEditItem = (HistoryEditItem)item;
					if (historyEditItem != null)
					{
						CommandData commandData = new CommandData((m_fastMode ? Point3.Zero : pos), historyEditItem.Line);
						commandData.TrySetValue();
						m_commandEditWidget.Initialize();
						m_commandEditWidget.SetCommandDataValue(commandData);
						m_commandEditWidget.ChangeExplains();
						m_commandEditWidget.GetDynamicCommanndWidget();
						m_commandEditWidget.SetCommandWidgetValue(commandData);
						CloseCurrentWidget();
					}
				}
			};
		}

		public override void Update()
		{
			m_filterLabel.Text = m_filter ? "收藏" : "全部";
			m_removeLabel.Text = m_filter ? "移除" : "清空";
			if (m_filter)
			{
				if (m_instructionlistWidget.SelectedItem == null)
				{
					m_removeRectangle.FillColor = new Color(64, 64, 64);
					m_clearButton.IsEnabled = false;
				}
				else
				{
					m_removeRectangle.FillColor = new Color(100, 100, 100);
					m_clearButton.IsEnabled = true;
				}
			}
			else
			{
				m_removeRectangle.FillColor = new Color(100, 100, 100);
				m_clearButton.IsEnabled = true;
			}
			if (m_okButton.IsClicked || base.Input.Cancel || base.Input.Back)
			{
				CloseCurrentWidget();
			}
			if (m_filterButton.IsClicked)
			{
				m_filter = !m_filter;
				UpdateItems();
			}
			if (m_clearButton.IsClicked)
			{
				if (m_filter)
				{
					HistoryEditItem historyEditItem = (HistoryEditItem)m_instructionlistWidget.SelectedItem;
					InstructionManager.RemoveHistoryItem(historyEditItem);
					UpdateItems();
				}
				else
				{
					DialogsManager.ShowDialog(m_commandEditWidget.m_componentPlayer.GuiWidget, new MessageDialog("是否清空所有指令历史记录", "注意：收藏的指令也会被清空", "确定", "取消", delegate (MessageDialogButton button)
					{
						if (button == MessageDialogButton.Button1)
						{
							InstructionManager.HistoryEditInstructions.Clear();
							InstructionManager.CollectionInstructions.Clear();
							m_instructionlistWidget.ClearItems();
						}
					}));
				}
			}
		}

		public void UpdateItems()
		{
			m_instructionlistWidget.ClearItems();
			if (m_filter)
			{
				List<HistoryEditItem> items = InstructionManager.CollectionInstructions;
				for (int i = items.Count - 1; i >= 0; i--)
				{
					if (m_fastMode && items[i].Condition) continue;
					m_instructionlistWidget.AddItem(items[i]);
				}
			}
			else
			{
				List<HistoryEditItem> items = InstructionManager.HistoryEditInstructions;
				int num = 0;
				for (int i = items.Count - 1; i >= 0; i--)
				{
					if (m_fastMode && items[i].Condition) continue;
					m_instructionlistWidget.AddItem(items[i]);
					if ((++num) >= 50) break;
				}
			}
		}

		public void CloseCurrentWidget()
		{
			base.ParentWidget.RemoveChildren(this);
			Time.QueueTimeDelayedExecution(Time.RealTime + 0.5f, delegate
			{
				m_commandEditWidget.IsEnabled = true;
			});
		}
	}

	//新的滑条界面
	public class CommandSliderWidget : CanvasWidget
	{
		public CanvasWidget m_canvasWidget;

		public CanvasWidget m_labelCanvasWidget;

		public Widget m_tabWidget;

		public TextBoxWidget m_textBoxWidget;

		public float m_minValue;

		public float m_maxValue = 1f;

		public float m_granularity = 1f;

		public float m_value;

		public float m_lastValue;

		public Vector2? m_dragStartPoint;

		public bool IsSliding
		{
			get;
			set;
		}

		public LayoutDirection LayoutDirection
		{
			get;
			set;
		}

		public float MinValue
		{
			get
			{
				return m_minValue;
			}
			set
			{
				if (value != m_minValue)
				{
					m_minValue = value;
					MaxValue = MathF.Max(MinValue, MaxValue);
					Value = Math.Clamp(Value, MinValue, MaxValue);
				}
			}
		}

		public float MaxValue
		{
			get
			{
				return m_maxValue;
			}
			set
			{
				if (value != m_maxValue)
				{
					m_maxValue = value;
					MinValue = MathF.Min(MinValue, MaxValue);
					Value = Math.Clamp(Value, MinValue, MaxValue);
				}
			}
		}

		public float Value
		{
			get
			{
				return m_value;
			}
			set
			{
				m_lastValue = m_value;
				m_value = m_granularity > 0f
					? (float)Math.Round(Math.Clamp(value, MinValue, MaxValue) / m_granularity) * m_granularity
					: Math.Clamp(value, MinValue, MaxValue);
			}
		}

		public float Granularity
		{
			get
			{
				return m_granularity;
			}
			set
			{
				m_granularity = MathF.Max(value, 0f);
			}
		}

		public string Text
		{
			get
			{
				return m_textBoxWidget.Text;
			}
			set
			{
				m_textBoxWidget.Text = value;
			}
		}

		public BitmapFont Font
		{
			get
			{
				return m_textBoxWidget.Font;
			}
			set
			{
				m_textBoxWidget.Font = value;
			}
		}

		public string SoundName
		{
			get;
			set;
		}

		public bool IsLabelVisible
		{
			get
			{
				return m_labelCanvasWidget.IsVisible;
			}
			set
			{
				m_labelCanvasWidget.IsVisible = value;
			}
		}

		public float LabelWidth
		{
			get
			{
				return m_labelCanvasWidget.Size.X;
			}
			set
			{
				m_labelCanvasWidget.Size = new Vector2(value, m_labelCanvasWidget.Size.Y);
			}
		}

		public CommandSliderWidget()
		{
			XElement node = ContentManager.Get<XElement>("Widgets/CommandSliderContents");
			LoadChildren(this, node);
			m_canvasWidget = Children.Find<CanvasWidget>("Slider.Canvas");
			m_labelCanvasWidget = Children.Find<CanvasWidget>("Slider.LabelCanvas");
			m_tabWidget = Children.Find<Widget>("Slider.Tab");
			m_textBoxWidget = Children.Find<TextBoxWidget>("Slider.TextBox");
			LoadProperties(this, node);
			m_lastValue = m_value;
			m_textBoxWidget.TextChanged += delegate (TextBoxWidget textBox)
			{
				if (int.TryParse(textBox.Text, out int num))
				{
					if (num >= MinValue && num <= MaxValue)
					{
						m_lastValue = num;
						m_value = num;
					}
					else if (num < MinValue)
					{
						m_lastValue = MinValue;
						m_value = MinValue;
					}
					else if (num > MaxValue)
					{
						m_lastValue = MaxValue;
						m_value = MaxValue;
					}
				}
				else
				{
					m_lastValue = MinValue;
					m_value = MinValue;
				}
			};
		}

		public override void MeasureOverride(Vector2 parentAvailableSize)
		{
			base.MeasureOverride(parentAvailableSize);
			IsDrawRequired = true;
		}

		public override void ArrangeOverride()
		{
			base.ArrangeOverride();
			float num = (LayoutDirection == LayoutDirection.Horizontal) ? m_canvasWidget.ActualSize.X : m_canvasWidget.ActualSize.Y;
			float num2 = (LayoutDirection == LayoutDirection.Horizontal) ? m_tabWidget.ActualSize.X : m_tabWidget.ActualSize.Y;
			float num3 = (MaxValue > MinValue) ? ((Value - MinValue) / (MaxValue - MinValue)) : 0f;
			if (LayoutDirection == LayoutDirection.Horizontal)
			{
				Vector2 zero = Vector2.Zero;
				zero.X = num3 * (num - num2);
				zero.Y = MathF.Max((ActualSize.Y - m_tabWidget.ActualSize.Y) / 2f, 0f);
				m_canvasWidget.SetWidgetPosition(m_tabWidget, zero);
			}
			else
			{
				Vector2 zero2 = Vector2.Zero;
				zero2.X = MathF.Max(ActualSize.X - m_tabWidget.ActualSize.X, 0f) / 2f;
				zero2.Y = num3 * (num - num2);
				m_canvasWidget.SetWidgetPosition(m_tabWidget, zero2);
			}
			base.ArrangeOverride();
		}

		public override void Update()
		{
			if (m_value != m_lastValue)
			{
				m_lastValue = m_value;
				m_textBoxWidget.Text = m_value + "";
			}
			float num = (LayoutDirection == LayoutDirection.Horizontal) ? m_canvasWidget.ActualSize.X : m_canvasWidget.ActualSize.Y;
			float num2 = (LayoutDirection == LayoutDirection.Horizontal) ? m_tabWidget.ActualSize.X : m_tabWidget.ActualSize.Y;
			if (Input.Tap.HasValue && HitTestGlobal(Input.Tap.Value) == m_tabWidget)
			{
				m_dragStartPoint = ScreenToWidget(Input.Press.Value);
			}
			if (Input.Press.HasValue)
			{
				if (m_dragStartPoint.HasValue)
				{
					Vector2 vector = ScreenToWidget(Input.Press.Value);
					float value = Value;
					if (LayoutDirection == LayoutDirection.Horizontal)
					{
						float f = (vector.X - num2 / 2f) / (num - num2);
						Value = MathUtils.Lerp(MinValue, MaxValue, f);
					}
					else
					{
						float f2 = (vector.Y - num2 / 2f) / (num - num2);
						Value = MathUtils.Lerp(MinValue, MaxValue, f2);
					}
					if (Value != value && m_granularity > 0f && !string.IsNullOrEmpty(SoundName))
					{
						AudioManager.PlaySound(SoundName, 1f, 0f, 0f);
					}
				}
			}
			else
			{
				m_dragStartPoint = null;
			}
			IsSliding = (m_dragStartPoint.HasValue && IsEnabledGlobal && IsVisibleGlobal);
			if (m_dragStartPoint.HasValue)
			{
				Input.Clear();
			}
		}
	}

	//新的滚动界面
	public class CommandScrollPanelWidget : ScrollPanelWidget
	{
		public override float CalculateScrollAreaLength()
		{
			float length = 0f;
			foreach (Widget child in Children)
			{
				if (child.IsVisible)
				{
					length = MathF.Max(length, child.ParentDesiredSize.X + 2f * child.Margin.X - 600f);
				}
			}
			return length;
		}
	}

	//新的挑选界面
	public class CommandListSelectionDialog : Dialog
	{
		public static IEnumerable m_oldItems;

		public Action<object, float> m_selectionHandler;

		public TextBoxWidget m_textBoxWidget;

		public LabelWidget m_titleLabelWidget;

		public ListPanelWidget m_listWidget;

		public CanvasWidget m_contentWidget;

		public ButtonWidget m_selectionCancelButton;

		public double? m_dismissTime;

		public bool m_isDismissed;

		public Vector2 ContentSize
		{
			get
			{
				return m_contentWidget.Size;
			}
			set
			{
				m_contentWidget.Size = value;
			}
		}

		public CommandListSelectionDialog(bool search, IEnumerable items, float itemSize, float scrollPosition, Func<object, Widget> itemWidgetFactory, Action<object, float> selectionHandler, Action<TextBoxWidget, ListPanelWidget> textBoxChange)
		{
			m_oldItems = items;
			m_selectionHandler = selectionHandler;
			XElement node = ContentManager.Get<XElement>("Widgets/CommandListSelectionDialog");
			LoadContents(this, node);
			m_titleLabelWidget = Children.Find<LabelWidget>("ListSelectionDialog.Title");
			m_listWidget = Children.Find<ListPanelWidget>("ListSelectionDialog.List");
			m_contentWidget = Children.Find<CanvasWidget>("ListSelectionDialog.Content");
			m_textBoxWidget = Children.Find<TextBoxWidget>("ListSelectionDialog.TextBox");
			m_selectionCancelButton = Children.Find<ButtonWidget>("SelectionCancel");
			Children.Find<StackPanelWidget>("SearchTextBox").IsVisible = search;
			Children.Find<CanvasWidget>("SearchInterval").IsVisible = search;
			m_titleLabelWidget.IsVisible = false;
			m_listWidget.ItemSize = itemSize;
			if (itemWidgetFactory != null)
			{
				m_listWidget.ItemWidgetFactory = itemWidgetFactory;
			}
			foreach (object item in items)
			{
				m_listWidget.AddItem(item);
			}
			int num = m_listWidget.Items.Count;
			float num2;
			while (true)
			{
				if (num >= 0)
				{
					num2 = MathF.Min(num + 0.5f, m_listWidget.Items.Count);
					if (num2 * itemSize <= m_contentWidget.Size.Y)
					{
						break;
					}
					num--;
					continue;
				}
				return;
			}
			m_contentWidget.Size = new Vector2(m_contentWidget.Size.X, num2 * itemSize);
			m_textBoxWidget.TextChanged += delegate (TextBoxWidget textBox)
			{
				if (textBoxChange != null)
				{
					textBoxChange.Invoke(textBox, m_listWidget);
				}
			};
			m_listWidget.ScrollPosition = scrollPosition;
		}

		public CommandListSelectionDialog(bool search, IEnumerable items, float itemSize, float scrollPosition, Func<object, string> itemToStringConverter, Action<object, float> selectionHandler, Action<TextBoxWidget, ListPanelWidget> textBoxChange)
			: this(search, items, itemSize, scrollPosition, (object item) => new LabelWidget
			{
				Text = itemToStringConverter(item),
				HorizontalAlignment = WidgetAlignment.Center,
				VerticalAlignment = WidgetAlignment.Center
			}, selectionHandler, textBoxChange)
		{
		}

		public override void Update()
		{
			if (Input.Back || Input.Cancel || m_selectionCancelButton.IsClicked)
			{
				m_dismissTime = 0.0;
			}
			else if (!m_dismissTime.HasValue && m_listWidget.SelectedItem != null)
			{
				m_dismissTime = Time.FrameStartTime + 0.05000000074505806;
			}
			if (m_dismissTime.HasValue && Time.FrameStartTime >= m_dismissTime.Value)
			{
				Dismiss(m_listWidget.SelectedItem);
			}
		}

		public void Dismiss(object result)
		{
			if (!m_isDismissed)
			{
				m_isDismissed = true;
				DialogsManager.HideDialog(this);
				if (m_selectionHandler != null && result != null)
				{
					m_selectionHandler(result, m_listWidget.ScrollPosition);
				}
			}
		}
	}

	//方块选择界面
	public class CommandBlockSelectionWidget : CanvasWidget
	{
		public class Category
		{
			public string Name;

			public Color Color = Color.White;

			public ContainerWidget Panel;
		}

		public List<Category> m_categories = new List<Category>();

		public int m_activeCategoryIndex = -1;

		public ComponentCreativeInventory m_componentCreativeInventory;

		public ButtonWidget m_pageUpButton;

		public ButtonWidget m_pageDownButton;

		public ButtonWidget m_categoryLeftButton;

		public ButtonWidget m_categoryRightButton;

		public ContainerWidget m_panelContainer;

		public LabelWidget m_categoryLabel;

		public RectangleWidget m_categoryLeftRectangle;

		public RectangleWidget m_categoryRightRectangle;

		public RectangleWidget m_pageUpRectangle;

		public RectangleWidget m_pageDownRectangle;

		public ButtonWidget m_blockSelectionCancel;

		public Entity Entity => m_componentCreativeInventory.Entity;

		public ButtonWidget PageDownButton => m_pageDownButton;

		public ButtonWidget PageUpButton => m_pageUpButton;

		public CommandEditWidget m_commandEditWidget;

		public string m_para;

		public static string fName = "CreativeInventoryWidget";

		public CommandBlockSelectionWidget(CommandEditWidget commandEditWidget, Entity entity, string para)
		{
			m_commandEditWidget = commandEditWidget;
			m_para = para;
			m_commandEditWidget.IsEnabled = false;
			m_componentCreativeInventory = entity.FindComponent<ComponentCreativeInventory>(throwOnError: true);
			XElement node = ContentManager.Get<XElement>("Widgets/CommandBlockSelectionWidget");
			LoadContents(this, node);
			m_categoryLeftButton = Children.Find<ButtonWidget>("CategoryLeftButton");
			m_categoryRightButton = Children.Find<ButtonWidget>("CategoryRightButton");
			m_pageUpButton = Children.Find<ButtonWidget>("PageUpButton");
			m_pageDownButton = Children.Find<ButtonWidget>("PageDownButton");
			m_panelContainer = Children.Find<ContainerWidget>("PanelContainer");
			m_categoryLabel = Children.Find<LabelWidget>("CategoryLabel");
			m_categoryLeftRectangle = Children.Find<RectangleWidget>("CategoryLeftRectangle");
			m_categoryRightRectangle = Children.Find<RectangleWidget>("CategoryRightRectangle");
			m_pageUpRectangle = Children.Find<RectangleWidget>("PageUpRectangle");
			m_pageDownRectangle = Children.Find<RectangleWidget>("PageDownRectangle");
			m_blockSelectionCancel = Children.Find<ButtonWidget>("BlockSelectionCancel");
			var creativeInventoryPanel = new CommandBlockPanel(this)
			{
				IsVisible = false
			};
			m_panelContainer.Children.Add(creativeInventoryPanel);
			foreach (string category in BlocksManager.Categories)
			{
				m_categories.Add(new Category
				{
					Name = category,
					Panel = creativeInventoryPanel
				});
			}
		}

		public string GetCategoryName(int index)
		{
			return m_categories[index].Name;
		}

		public override void Update()
		{
			if (m_categoryLeftButton.IsClicked || Input.Left)
			{
				--m_componentCreativeInventory.CategoryIndex;
			}
			if (m_categoryRightButton.IsClicked || Input.Right)
			{
				++m_componentCreativeInventory.CategoryIndex;
			}
			m_componentCreativeInventory.CategoryIndex = Math.Clamp(m_componentCreativeInventory.CategoryIndex, 0, m_categories.Count - 1);
			m_categoryLabel.Text = LanguageControl.Get("BlocksManager", m_categories[m_componentCreativeInventory.CategoryIndex].Name);
			if (m_componentCreativeInventory.CategoryIndex > 0)
			{
				m_categoryLeftButton.IsEnabled = true;
				m_categoryLeftRectangle.FillColor = new Color(100, 100, 100);
			}
			else
			{
				m_categoryLeftButton.IsEnabled = false;
				m_categoryLeftRectangle.FillColor = new Color(80, 80, 80);
			}
			if (m_componentCreativeInventory.CategoryIndex < m_categories.Count - 1)
			{
				m_categoryRightButton.IsEnabled = true;
				m_categoryRightRectangle.FillColor = new Color(100, 100, 100);
			}
			else
			{
				m_categoryRightButton.IsEnabled = false;
				m_categoryRightRectangle.FillColor = new Color(80, 80, 80);
			}
			if (m_componentCreativeInventory.CategoryIndex != m_activeCategoryIndex)
			{
				foreach (Category category in m_categories)
				{
					category.Panel.IsVisible = false;
				}
				m_categories[m_componentCreativeInventory.CategoryIndex].Panel.IsVisible = true;
				m_activeCategoryIndex = m_componentCreativeInventory.CategoryIndex;
			}
			if (m_blockSelectionCancel.IsClicked || base.Input.Cancel || base.Input.Back)
			{
				CloseCurrentWidget();
			}
		}

		public void CloseCurrentWidget()
		{
			base.ParentWidget.RemoveChildren(this);
			Time.QueueTimeDelayedExecution(Time.RealTime + 0.5f, delegate
			{
				m_commandEditWidget.IsEnabled = true;
			});
		}
	}

	//新的方块面板
	public class CommandBlockPanel : CanvasWidget
	{
		public CommandBlockSelectionWidget m_creativeInventoryWidget;

		public ComponentCreativeInventory m_componentCreativeInventory;

		public List<int> m_slotIndices = new List<int>();

		public GridPanelWidget m_inventoryGrid;

		public int m_pagesCount;

		public int m_assignedCategoryIndex = -1;

		public int m_assignedPageIndex = -1;

		public CommandBlockPanel(CommandBlockSelectionWidget creativeInventoryWidget)
		{
			m_creativeInventoryWidget = creativeInventoryWidget;
			m_componentCreativeInventory = creativeInventoryWidget.Entity.FindComponent<ComponentCreativeInventory>(throwOnError: true);
			XElement node = ContentManager.Get<XElement>("Widgets/CreativeInventoryPanel");
			LoadContents(this, node);
			m_inventoryGrid = Children.Find<GridPanelWidget>("InventoryGrid");
			for (int i = 0; i < m_inventoryGrid.RowsCount; i++)
			{
				for (int j = 0; j < m_inventoryGrid.ColumnsCount; j++)
				{
					XElement node2 = ContentManager.Get<XElement>("Widgets/CommandBlockSlot");
					ContainerWidget widget = (ContainerWidget)LoadWidget(this, node2, null);
					BlockIconWidget blockSlot = widget.Children.Find<BlockIconWidget>("BlockSlot.Icon");
					blockSlot.Value = 0;
					m_inventoryGrid.Children.Add(widget);
					m_inventoryGrid.SetWidgetCell(widget, new Point2(j, i));
				}
			}
		}

		public override void Update()
		{
			if (m_assignedCategoryIndex >= 0)
			{
				if (Input.Scroll.HasValue)
				{
					Widget widget = HitTestGlobal(Input.Scroll.Value.XY);
					if (widget != null && widget.IsChildWidgetOf(m_inventoryGrid))
					{
						m_componentCreativeInventory.PageIndex -= (int)Input.Scroll.Value.Z;
					}
				}
				if (m_creativeInventoryWidget.PageDownButton.IsClicked)
				{
					++m_componentCreativeInventory.PageIndex;
				}
				if (m_creativeInventoryWidget.PageUpButton.IsClicked)
				{
					--m_componentCreativeInventory.PageIndex;
				}
				m_componentCreativeInventory.PageIndex = ((m_pagesCount > 0) ? Math.Clamp(m_componentCreativeInventory.PageIndex, 0, m_pagesCount - 1) : 0);
			}
			if (m_componentCreativeInventory.CategoryIndex != m_assignedCategoryIndex)
			{
				if (m_creativeInventoryWidget.GetCategoryName(m_componentCreativeInventory.CategoryIndex) == LanguageControl.Get("CreativeInventoryWidget", 2))
				{
					m_slotIndices = new List<int>(Enumerable.Range(10, m_componentCreativeInventory.OpenSlotsCount - 10));
				}
				else
				{
					m_slotIndices.Clear();
					for (int i = m_componentCreativeInventory.OpenSlotsCount; i < m_componentCreativeInventory.SlotsCount; i++)
					{
						int slotValue = m_componentCreativeInventory.GetSlotValue(i);
						int num2 = Terrain.ExtractContents(slotValue);
						if (BlocksManager.Blocks[num2].GetCategory(slotValue) == m_creativeInventoryWidget.GetCategoryName(m_componentCreativeInventory.CategoryIndex))
						{
							m_slotIndices.Add(i);
						}
					}
				}
				int num3 = m_inventoryGrid.ColumnsCount * m_inventoryGrid.RowsCount;
				m_pagesCount = (m_slotIndices.Count + num3 - 1) / num3;
				m_assignedCategoryIndex = m_componentCreativeInventory.CategoryIndex;
				m_assignedPageIndex = -1;
				m_componentCreativeInventory.PageIndex = 0;
			}
			if (m_componentCreativeInventory.PageIndex != m_assignedPageIndex)
			{
				int num4 = m_inventoryGrid.ColumnsCount * m_inventoryGrid.RowsCount;
				int num5 = m_componentCreativeInventory.PageIndex * num4;
				foreach (Widget child in m_inventoryGrid.Children)
				{
					var widget = child as ContainerWidget;
					BlockIconWidget blockIconWidget = widget.Children.Find<BlockIconWidget>("BlockSlot.Icon");
					if (widget != null)
					{
						if (num5 < m_slotIndices.Count)
						{
							blockIconWidget.Value = m_componentCreativeInventory.GetSlotValue(m_slotIndices[num5++]);
						}
						else
						{
							blockIconWidget.Value = 0;
						}
					}
				}
				m_assignedPageIndex = m_componentCreativeInventory.PageIndex;
			}
			foreach (Widget child in m_inventoryGrid.Children)
			{
				var widget = child as ContainerWidget;
				if (widget != null)
				{
					ButtonWidget buttonWidget = widget.Children.Find<ButtonWidget>("BlockSlot.Button");
					if (buttonWidget.IsClicked)
					{
						BlockIconWidget blockSlot = widget.Children.Find<BlockIconWidget>("BlockSlot.Icon");
						TextBoxWidget textBoxWidget = (TextBoxWidget)m_creativeInventoryWidget.m_commandEditWidget.m_commandWidgetDatas["TextBox$" + m_creativeInventoryWidget.m_para];
						BlockIconWidget blockIconWidget = (BlockIconWidget)m_creativeInventoryWidget.m_commandEditWidget.m_commandWidgetDatas["BlockIcon$" + m_creativeInventoryWidget.m_para];
						textBoxWidget.Text = blockSlot.Value + "";
						blockIconWidget.Value = blockSlot.Value;
						m_creativeInventoryWidget.CloseCurrentWidget();
					}
				}
			}
			if (m_componentCreativeInventory.PageIndex < m_pagesCount - 1)
			{
				m_creativeInventoryWidget.PageDownButton.IsEnabled = true;
				m_creativeInventoryWidget.m_pageDownRectangle.FillColor = new Color(100, 100, 100);
			}
			else
			{
				m_creativeInventoryWidget.PageDownButton.IsEnabled = false;
				m_creativeInventoryWidget.m_pageDownRectangle.FillColor = new Color(80, 80, 80);
			}
			if (m_componentCreativeInventory.PageIndex > 0)
			{
				m_creativeInventoryWidget.PageUpButton.IsEnabled = true;
				m_creativeInventoryWidget.m_pageUpRectangle.FillColor = new Color(100, 100, 100);
			}
			else
			{
				m_creativeInventoryWidget.PageUpButton.IsEnabled = false;
				m_creativeInventoryWidget.m_pageUpRectangle.FillColor = new Color(80, 80, 80);
			}
		}
	}

	//生物选择界面
	public class CommandEntitySelectionWidget : CanvasWidget
	{
		public ButtonWidget m_selectionCancelButton;

		public ButtonWidget m_orderButton;

		public ListPanelWidget m_entitylistWidget;

		public CommandEditWidget m_commandEditWidget;

		public static List<EntityInfo> EntityInfoDescList = new List<EntityInfo>();

		public bool m_direction;

		public string m_para;

		public CommandEntitySelectionWidget(CommandEditWidget commandEditWidget, string para)
		{
			m_commandEditWidget = commandEditWidget;
			m_para = para;
			m_commandEditWidget.IsEnabled = false;
			XElement node = ContentManager.Get<XElement>("Widgets/CommandEntitySelectionWidget");
			LoadContents(this, node);
			m_selectionCancelButton = Children.Find<ButtonWidget>("SelectionCancel");
			m_orderButton = Children.Find<ButtonWidget>("Order");
			m_entitylistWidget = Children.Find<ListPanelWidget>("CreaturesList");
			m_direction = true;
			if (EntityInfoDescList.Count == 0)
			{
				EntityInfo[] EntityInfoArray = EntityInfoManager.EntityInfos.Values.ToArray();
				for (int i = EntityInfoArray.Length - 1; i >= 0; i--)
				{
					EntityInfoDescList.Add(EntityInfoArray[i]);
				}
			}
			foreach (EntityInfo modelInfo in EntityInfoManager.EntityInfos.Values)
			{
				m_entitylistWidget.AddItem(modelInfo);
			}
			m_entitylistWidget.ItemWidgetFactory = delegate (object item)
			{
				EntityInfo info = (EntityInfo)item;
				XElement node2 = ContentManager.Get<XElement>("Widgets/CommandEntityItem");
				ContainerWidget containerWidget = (ContainerWidget)LoadWidget(this, node2, null);
				LabelWidget labelWidget = containerWidget.Children.Find<LabelWidget>("ModelLabel");
				labelWidget.Text = info.KeyName + " : " + info.DisplayName;
				ModelWidget modelWidget = containerWidget.Children.Find<ModelWidget>("ModelIcon");
				EntityInfoManager.ChangeModelDisplay(ref modelWidget, info.Model, info.Texture);
				return containerWidget;
			};
			m_entitylistWidget.ItemClicked += delegate (object item)
			{
				if (item != null)
				{
					EntityInfo info = (EntityInfo)item;
					TextBoxWidget textBoxWidget = (TextBoxWidget)m_commandEditWidget.m_commandWidgetDatas["TextBox$" + m_para];
					ModelWidget modelWidget = (ModelWidget)m_commandEditWidget.m_commandWidgetDatas["Model$" + m_para];
					textBoxWidget.Text = info.KeyName;
					EntityInfoManager.ChangeModelDisplay(ref modelWidget, info.Model, info.Texture);
					CloseCurrentWidget();
				}
			};
		}

		public override void Update()
		{
			if (m_orderButton.IsClicked)
			{
				m_direction = !m_direction;
				m_entitylistWidget.ClearItems();
				if (m_direction)
				{
					foreach (EntityInfo modelInfo in EntityInfoManager.EntityInfos.Values)
					{
						m_entitylistWidget.AddItem(modelInfo);
					}
				}
				else
				{
					foreach (EntityInfo modelInfo in EntityInfoDescList)
					{
						m_entitylistWidget.AddItem(modelInfo);
					}
				}
			}
			if (m_selectionCancelButton.IsClicked || base.Input.Cancel || base.Input.Back)
			{
				CloseCurrentWidget();
			}
		}

		public void CloseCurrentWidget()
		{
			Time.QueueTimeDelayedExecution(Time.RealTime + 0.05f, delegate
			{
				base.ParentWidget.RemoveChildren(this);
			});
			Time.QueueTimeDelayedExecution(Time.RealTime + 0.5f, delegate
			{
				m_commandEditWidget.IsEnabled = true;
			});
		}
	}

	//颜色选择界面
	public class CommandColorSelectionWidget : CanvasWidget
	{
		public ButtonWidget m_selectionOkButton;

		public ButtonWidget m_selectionCancelButton;

		public RectangleWidget m_colorDisplayRectangle;

		public CommandSliderWidget m_commandSliderR;

		public CommandSliderWidget m_commandSliderG;

		public CommandSliderWidget m_commandSliderB;

		public CommandEditWidget m_commandEditWidget;

		public string m_para;

		public CommandColorSelectionWidget(CommandEditWidget commandEditWidget, string para)
		{
			m_commandEditWidget = commandEditWidget;
			m_para = para;
			m_commandEditWidget.IsEnabled = false;
			XElement node = ContentManager.Get<XElement>("Widgets/CommandColorSelectionWidget");
			LoadContents(this, node);
			m_selectionOkButton = Children.Find<ButtonWidget>("SelectionOk");
			m_selectionCancelButton = Children.Find<ButtonWidget>("SelectionCancel");
			m_colorDisplayRectangle = Children.Find<RectangleWidget>("ColorDisplay");
			m_commandSliderR = Children.Find<CommandSliderWidget>("ColorSlider.R");
			m_commandSliderG = Children.Find<CommandSliderWidget>("ColorSlider.G");
			m_commandSliderB = Children.Find<CommandSliderWidget>("ColorSlider.B");
			m_commandSliderR.IsLabelVisible = false;
			m_commandSliderG.IsLabelVisible = false;
			m_commandSliderB.IsLabelVisible = false;
			m_commandSliderR.MinValue = 0;
			m_commandSliderG.MinValue = 0;
			m_commandSliderB.MinValue = 0;
			m_commandSliderR.MaxValue = 255;
			m_commandSliderG.MaxValue = 255;
			m_commandSliderB.MaxValue = 255;
			RectangleWidget rectangleWidget = (RectangleWidget)commandEditWidget.m_commandWidgetDatas["Rectangle$" + para];
			m_commandSliderR.Value = rectangleWidget.FillColor.R;
			m_commandSliderG.Value = rectangleWidget.FillColor.G;
			m_commandSliderB.Value = rectangleWidget.FillColor.B;
			m_colorDisplayRectangle.FillColor = new Color(80, 80, 80);
		}

		public override void Update()
		{
			m_colorDisplayRectangle.FillColor = new Color((int)m_commandSliderR.Value, (int)m_commandSliderG.Value, (int)m_commandSliderB.Value);
			if (m_selectionOkButton.IsClicked)
			{
				RectangleWidget rectangleWidget = (RectangleWidget)m_commandEditWidget.m_commandWidgetDatas["Rectangle$" + m_para];
				TextBoxWidget textBoxWidget = (TextBoxWidget)m_commandEditWidget.m_commandWidgetDatas["TextBox$" + m_para];
				rectangleWidget.FillColor = m_colorDisplayRectangle.FillColor;
				textBoxWidget.Text = m_colorDisplayRectangle.FillColor.ToString();
				CloseCurrentWidget();
			}
			if (m_selectionCancelButton.IsClicked || base.Input.Cancel || base.Input.Back)
			{
				CloseCurrentWidget();
			}
		}

		public void CloseCurrentWidget()
		{
			base.ParentWidget.RemoveChildren(this);
			Time.QueueTimeDelayedExecution(Time.RealTime + 0.5f, delegate
			{
				m_commandEditWidget.IsEnabled = true;
			});
		}
	}

	//二项选择界面
	public class CommandSwitchWidget : CanvasWidget
	{
		public ButtonWidget m_falseButton;

		public ButtonWidget m_trueButton;

		public RectangleWidget m_falseRectangle;

		public RectangleWidget m_trueRectangle;

		public string m_checkLabelText;

		public CommandSwitchWidget()
		{
			XElement node = ContentManager.Get<XElement>("Widgets/CommandSwitchWidget");
			LoadContents(this, node);
			m_falseButton = Children.Find<ButtonWidget>("CommandData.FalseButton");
			m_trueButton = Children.Find<ButtonWidget>("CommandData.TrueButton");
			m_falseRectangle = Children.Find<RectangleWidget>("CommandData.FalseRectangle");
			m_trueRectangle = Children.Find<RectangleWidget>("CommandData.TrueRectangle");
			m_checkLabelText = "true";
		}

		public override void Update()
		{
			if (m_checkLabelText == "true")
			{
				m_trueRectangle.FillColor = new Color(100, 100, 100);
				m_falseRectangle.FillColor = new Color(80, 80, 80);
			}
			else
			{
				m_falseRectangle.FillColor = new Color(100, 100, 100);
				m_trueRectangle.FillColor = new Color(80, 80, 80);
			}
			if (m_falseButton.IsClicked)
			{
				m_checkLabelText = "false";
			}
			if (m_trueButton.IsClicked)
			{
				m_checkLabelText = "true";
			}
		}
	}

	//手册界面
	public class ManualTopicWidget : CanvasWidget
	{
		public class InformationTopic
		{
			public string Title;
			public string Details;
			public int Index;
		}

		public static List<InformationTopic> InformationTopicList = new List<InformationTopic>();

		public ListPanelWidget m_informationsWidget;

		public ButtonWidget m_okButton;

		public ComponentPlayer m_componentPlayer;

		public ManualTopicWidget(ComponentPlayer componentPlayer, float scroll)
		{
			m_componentPlayer = componentPlayer;
			XElement node = ContentManager.Get<XElement>("Widgets/ManualTopicWidget");
			LoadContents(this, node);
			m_okButton = Children.Find<ButtonWidget>("OkButton");
			m_informationsWidget = Children.Find<ListPanelWidget>("Information.List");
			m_informationsWidget.ItemWidgetFactory = delegate (object item)
			{
				InformationTopic informationTopic = (InformationTopic)item;
				XElement node2 = ContentManager.Get<XElement>("Widgets/ManualItem");
				ContainerWidget containerWidget = (ContainerWidget)LoadWidget(this, node2, null);
				containerWidget.Children.Find<LabelWidget>("InformationTopic.Title").Text = informationTopic.Title;
				return containerWidget;
			};
			m_informationsWidget.ScrollPosition = scroll;
			m_informationsWidget.ItemClicked += delegate (object item)
			{
				InformationTopic informationTopic = (InformationTopic)item;
				m_componentPlayer.ComponentGui.ModalPanelWidget = new ManualDetailsWidget(m_componentPlayer, informationTopic, m_informationsWidget.ScrollPosition);
			};
			foreach (InformationTopic item in InformationTopicList)
			{
				m_informationsWidget.AddItem(item);
			}
		}

		public override void Update()
		{
			if (m_okButton.IsClicked)
			{
				m_componentPlayer.ComponentGui.ModalPanelWidget = null;
			}
		}

		public static void LoadInformationTopics()
		{
			XElement xInformation = ContentManager.Get<XElement>("Information");
			List<XElement> xInformations = xInformation.Elements("Topic").ToList();
			int index = 0;
			foreach (XElement x in xInformations)
			{
				InformationTopic informationTopic = new InformationTopic();
				informationTopic.Title = x.Attribute("Title").Value;
				informationTopic.Details = x.Value.Trim('\n').Replace("\t", "");
				informationTopic.Index = index++;
				InformationTopicList.Add(informationTopic);
			}
		}

		public static InformationTopic GetInformationTopicByIndex(int index)
		{
			foreach (InformationTopic topic in InformationTopicList)
			{
				if (topic.Index == index)
				{
					return topic;
				}
			}
			return null;
		}
	}

	//手册详情界面
	public class ManualDetailsWidget : CanvasWidget
	{
		public LabelWidget m_titleLabel;

		public LabelWidget m_detailsLabel;

		public ButtonWidget m_lastButton;

		public ButtonWidget m_nextButton;

		public ButtonWidget m_backButton;

		public ComponentPlayer m_componentPlayer;

		public int m_topicIndex;

		public float parentScroll;

		public ManualDetailsWidget(ComponentPlayer componentPlayer, ManualTopicWidget.InformationTopic informationTopic, float scroll)
		{
			m_componentPlayer = componentPlayer;
			m_topicIndex = informationTopic.Index;
			parentScroll = scroll;
			XElement node = ContentManager.Get<XElement>("Widgets/ManualDetailsWidget");
			LoadContents(this, node);
			m_backButton = Children.Find<ButtonWidget>("BackButton");
			m_lastButton = Children.Find<ButtonWidget>("LastButton");
			m_nextButton = Children.Find<ButtonWidget>("NextButton");
			m_titleLabel = Children.Find<LabelWidget>("InformationTopic.Title");
			m_detailsLabel = Children.Find<LabelWidget>("InformationTopic.Details");
			m_titleLabel.Text = informationTopic.Title;
			m_detailsLabel.Text = informationTopic.Details;
		}

		public override void Update()
		{
			if (m_lastButton.IsClicked)
			{
				var informationTopic = ManualTopicWidget.GetInformationTopicByIndex(m_topicIndex - 1);
				if (informationTopic != null)
				{
					m_titleLabel.Text = informationTopic.Title;
					m_detailsLabel.Text = informationTopic.Details;
					m_topicIndex--;
				}
			}
			if (m_nextButton.IsClicked)
			{
				var informationTopic = ManualTopicWidget.GetInformationTopicByIndex(m_topicIndex + 1);
				if (informationTopic != null)
				{
					m_titleLabel.Text = informationTopic.Title;
					m_detailsLabel.Text = informationTopic.Details;
					m_topicIndex++;
				}
			}
			if (m_backButton.IsClicked)
			{
				m_componentPlayer.ComponentGui.ModalPanelWidget = new ManualTopicWidget(m_componentPlayer, parentScroll);
			}
		}
	}

	//记事本界面
	public class NotesWidget : CanvasWidget
	{
		public LabelWidget m_contentLabel;

		public ButtonWidget m_okButton;

		public ButtonWidget m_LButton;

		public ButtonWidget m_RButton;

		public ButtonWidget m_editButton;

		public ButtonWidget m_removeButton;

		public ButtonWidget m_addButton;

		public RectangleWidget m_reftRectangle;

		public RectangleWidget m_rightRectangle;

		public static Dictionary<string, string> m_notes;

		public ComponentPlayer m_componentPlayer;

		public int m_index;

		public NotesWidget(ComponentPlayer componentPlayer, Dictionary<string, string> notes)
		{
			m_componentPlayer = componentPlayer;
			m_notes = notes;
			XElement node = ContentManager.Get<XElement>("Widgets/NotesWidget");
			LoadContents(this, node);
			m_LButton = Children.Find<ButtonWidget>("LButton");
			m_RButton = Children.Find<ButtonWidget>("RButton");
			m_editButton = Children.Find<ButtonWidget>("EditButton");
			m_removeButton = Children.Find<ButtonWidget>("RemoveButton");
			m_addButton = Children.Find<ButtonWidget>("AddButton");
			m_okButton = Children.Find<ButtonWidget>("OkButton");
			m_contentLabel = Children.Find<LabelWidget>("Content");
			m_reftRectangle = Children.Find<RectangleWidget>("Left");
			m_rightRectangle = Children.Find<RectangleWidget>("Right");
			m_index = 0;
			m_contentLabel.Text = ShowText(m_index);
		}

		public override void Update()
		{
			m_LButton.IsEnabled = (m_index > 0);
			m_RButton.IsEnabled = (m_index < m_notes.Count - 1);
			m_reftRectangle.FillColor = (m_index > 0) ? new Color(100, 100, 100) : new Color(64, 64, 64);
			m_rightRectangle.FillColor = ((m_index < m_notes.Count - 1)) ? new Color(100, 100, 100) : new Color(64, 64, 64);
			if (m_LButton.IsClicked)
			{
				m_index--;
				var n = m_notes.ElementAt(m_index);
				m_contentLabel.Text = ShowText(m_index);
			}
			if (m_RButton.IsClicked)
			{
				m_index++;
				var n = m_notes.ElementAt(m_index);
				m_contentLabel.Text = ShowText(m_index);
			}
			if (m_editButton.IsClicked)
			{
				if (m_notes.Count == 0) return;
				var n = m_notes.ElementAt(m_index);
				DialogsManager.ShowDialog(m_componentPlayer.GuiWidget, new CommandEditNotesDialog(this, n.Key, delegate (string t, string s)
				{
					try
					{
						if (s != null)
						{
							if (t != n.Key)
							{
								m_notes.Remove(n.Key);
							}
							m_notes[t] = s;
							m_index = m_notes.Keys.FirstIndex(t);
							m_contentLabel.Text = ShowText(m_index);
						}
					}
					catch
					{
					}
				}));
			}
			if (m_removeButton.IsClicked)
			{
				if (m_notes.Count == 0) return;
				var n = m_notes.ElementAt(m_index);
				DialogsManager.ShowDialog(m_componentPlayer.GuiWidget, new MessageDialog(string.Format("是否删除标题为{0}的笔记", n.Key), string.Empty, "确定", "取消", delegate (MessageDialogButton button)
				{
					if (button == MessageDialogButton.Button1)
					{
						m_notes.Remove(n.Key);
						m_index = 0;
						m_contentLabel.Text = ShowText(m_index);
					}
				}));
			}
			if (m_addButton.IsClicked)
			{
				DialogsManager.ShowDialog(m_componentPlayer.GuiWidget, new TextBoxDialog("请输入笔记标题", string.Empty, 256, delegate (string title)
				{
					try
					{
						if (!string.IsNullOrEmpty(title))
						{
							if (m_notes.TryGetValue(title, out string value))
							{
								m_notes[title] = value;
							}
							else
							{
								m_notes[title] = string.Empty;
							}
							DialogsManager.ShowDialog(m_componentPlayer.GuiWidget, new CommandEditNotesDialog(this, title, delegate (string t, string s)
							{
								try
								{
									if (s != null)
									{
										if (t != title)
										{
											m_notes.Remove(title);
										}
										m_notes[t] = s;
										m_index = m_notes.Keys.FirstIndex(t);
										m_contentLabel.Text = ShowText(m_index);
									}
								}
								catch
								{
								}
							}));
						}
					}
					catch
					{
					}
				}));
			}
			if (m_okButton.IsClicked)
			{
				base.ParentWidget.RemoveChildren(this);
			}
		}

		public string ShowText(int index)
		{
			if (m_notes.Count > 0)
			{
				var n = m_notes.ElementAt(index);
				return "\n标题：" + n.Key + "\n\n" + n.Value.Replace("[n]", "\n").Replace("\t", "");
			}
			else
			{
				return "\n\n未找到编写过的笔记，请添加笔记内容";
			}
		}
	}

	//记事本编辑会话界面
	public class CommandEditNotesDialog : Dialog
	{
		public Action<string, string> m_handler;

		public LabelWidget m_titleWidget;

		public TextBoxWidget m_textBoxWidget;

		public ButtonWidget m_okButtonWidget;

		public ButtonWidget m_cancelButtonWidget;

		public ButtonWidget m_titleButtonWidget;

		public ButtonWidget m_copyButtonWidget;

		public ButtonWidget m_pasteButtonWidget;

		public ButtonWidget m_clearButtonWidget;

		public NotesWidget m_notesWidget;

		public bool AutoHide
		{
			get;
			set;
		}

		public string m_title;

		public CommandEditNotesDialog(NotesWidget notesWidget, string title, Action<string, string> handler)
		{
			m_notesWidget = notesWidget;
			m_title = title;
			m_handler = handler;
			XElement node = ContentManager.Get<XElement>("Widgets/CommandEditNotes");
			LoadContents(this, node);
			m_titleWidget = Children.Find<LabelWidget>("TextBoxDialog.Title");
			m_textBoxWidget = Children.Find<TextBoxWidget>("TextBoxDialog.TextBox");
			m_okButtonWidget = Children.Find<ButtonWidget>("TextBoxDialog.OkButton");
			m_cancelButtonWidget = Children.Find<ButtonWidget>("TextBoxDialog.CancelButton");
			m_titleButtonWidget = Children.Find<ButtonWidget>("TextBoxDialog.TitleButton");
			m_copyButtonWidget = Children.Find<ButtonWidget>("TextBoxDialog.CopyButton");
			m_pasteButtonWidget = Children.Find<ButtonWidget>("TextBoxDialog.PasteButton");
			m_clearButtonWidget = Children.Find<ButtonWidget>("TextBoxDialog.ClearButton");
			m_titleWidget.IsVisible = !string.IsNullOrEmpty(title);
			m_titleWidget.Text = "编辑笔记内容:" + title;
			m_textBoxWidget.MaximumLength = 5000;
			m_textBoxWidget.Text = (NotesWidget.m_notes[title] ?? string.Empty);
			m_textBoxWidget.HasFocus = true;
			m_textBoxWidget.Text = m_textBoxWidget.Text.Replace("\n", "[n]");
			m_textBoxWidget.Text = m_textBoxWidget.Text.Replace("\r", "");
			m_textBoxWidget.TextChanged += delegate (TextBoxWidget textBox)
			{
				textBox.Text = textBox.Text.Replace("\n", "[n]");
			};
			m_textBoxWidget.Enter += delegate
			{
				Dismiss(m_textBoxWidget.Text);
			};
			AutoHide = true;
		}

		public override void Update()
		{
			if (Input.Cancel)
			{
				Dismiss(null);
			}
			else if (Input.Ok)
			{
				Dismiss(m_textBoxWidget.Text);
			}
			else if (m_okButtonWidget.IsClicked)
			{
				Dismiss(m_textBoxWidget.Text);
			}
			else if (m_cancelButtonWidget.IsClicked)
			{
				Dismiss(null);
			}
			if (m_copyButtonWidget.IsClicked)
			{
				ClipboardManager.ClipboardString = m_textBoxWidget.Text;
			}
			if (m_pasteButtonWidget.IsClicked)
			{
				m_textBoxWidget.Text = ClipboardManager.ClipboardString;
			}
			if (m_clearButtonWidget.IsClicked)
			{
				m_textBoxWidget.Text = string.Empty;
			}
			if (m_titleButtonWidget.IsClicked)
			{
				DialogsManager.ShowDialog(m_notesWidget.m_componentPlayer.GuiWidget, new TextBoxDialog("请重新输入笔记标题", m_title, 256, delegate (string title)
				{
					if (title != null)
					{
						m_titleWidget.Text = "编辑笔记内容:" + title;
						m_title = title;
					}
				}));
			}
		}

		public void Dismiss(string result)
		{
			if (!string.IsNullOrEmpty(result))
			{
				result = result.Replace("\r", "");
			}
			if (AutoHide)
			{
				DialogsManager.HideDialog(this);
			}
			m_handler?.Invoke(m_title, result);
		}
	}
}